package cn.laike.modules.dev.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import cn.laike.common.utils.PageUtils;
import cn.laike.common.utils.Query;
import cn.laike.modules.dev.dao.MobileMessageRecorderDao;
import cn.laike.modules.dev.entity.MobileMessageRecorderEntity;
import cn.laike.modules.dev.service.MobileMessageRecorderService;
import cn.laike.modules.sys.shiro.ShiroUtils;


@Service("mobileMessageRecorderService")
public class MobileMessageRecorderServiceImpl extends ServiceImpl<MobileMessageRecorderDao, MobileMessageRecorderEntity> implements MobileMessageRecorderService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
    	String mobile = (String)params.get("mobile");
        Page<MobileMessageRecorderEntity> page = this.selectPage(
                new Query<MobileMessageRecorderEntity>(params).getPage(),
                new EntityWrapper<MobileMessageRecorderEntity>()
                .eq(StringUtils.isNotBlank(mobile),"mobile", mobile)
                .eq(ShiroUtils.isAdmin(),"uid", ShiroUtils.getUserId())
                .orderBy("id", false)
        );

        return new PageUtils(page);
    }

	@Override
	public MobileMessageRecorderEntity getByMobileAndCode(String mobile, String code) {
		List<MobileMessageRecorderEntity> list = this.selectList(new EntityWrapper<MobileMessageRecorderEntity>()
    			.eq("mobile", mobile)
    			.eq("verification_code", code));
    	return (list != null && list.size() > 0) ? list.get(0) : null;
	}

}
